/**
 * https://codeforces.com/problemset/problem/1904/C
 */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll t;
	ll n;
	ll k;
	cin>>t;
	while(t--){
		cin>>n>>k;
		vector<ll>a(n);
		for(ll i=0;i<n;++i)
		cin>>a[i];
		if(k>=3){
			cout<<0<<endl;
			continue;
		}
		sort(a.begin(),a.end());
		ll d=a[0];
		for(ll i=1;i<n;++i)
		d=min(d,a[i]-a[i-1]);
		if(k==1){
			cout<<d<<endl;
			continue;
		}
		for(ll i=1;i<n;++i){
			for(ll j=0;j<i;++j){
				ll k=a[i]-a[j];
				ll p=lower_bound(a.begin(),a.end(),k)-a.begin();
				if(p<n)
				d=min(d,a[p]-k);
				if(p>0)
				d=min(d,k-a[p-1]);
			}
		}
		cout<<d<<endl;
	}
	return 0;
}